

#pragma once

#include "../DefinesCore.hpp"

CYBERTRON_BEGIN

class NetworkActionBase : public std::enable_shared_from_this<NetworkActionBase>
{
public:
	CybertronCoreAPI NetworkActionBase();
	CybertronCoreAPI virtual ~NetworkActionBase();

public:
	CybertronCoreAPI void setTimeout(int millisecondsTimeout);
	CybertronCoreAPI int getTimeout() const;
	CybertronCoreAPI void setSocket(std::shared_ptr<SocketBase> pSocket);
	CybertronCoreAPI void setDesiredMessageId(std::uint16_t desiredMessageId);

public:
	CybertronCoreAPI void setStart();
	CybertronCoreAPI void setEnd();

	CybertronCoreAPI void handleTimer(int ms);
	CybertronCoreAPI void handleMessage(Message& msg);

public:
	CybertronCoreAPI bool getStarted() const;
	CybertronCoreAPI bool getEnded() const;
	CybertronCoreAPI int getMillisecondsPassed() const;
	CybertronCoreAPI std::uint16_t getDesiredMessageId() const;
	CybertronCoreAPI std::shared_ptr<SocketBase> getSocket() const;

protected:
	CybertronCoreAPI virtual void onStart();
	CybertronCoreAPI virtual void onTimer(int ms);
	CybertronCoreAPI virtual void onTimeout();
	CybertronCoreAPI virtual void onDesiredMessage(Message& msg);
	CybertronCoreAPI virtual void onMessage(Message& msg);
	CybertronCoreAPI virtual void onEnd();

private:
	void zeroMembers();

private:
	NetworkActionBase(const NetworkActionBase&);
	NetworkActionBase& operator = (const NetworkActionBase&);

private:
	bool mStarted;
	bool mEnded;
	std::uint16_t mDesiredMessageId;
	int mMillisecondsPassed;
	int mMillisecondsTimeout;
	std::weak_ptr<SocketBase> mpSocket;
};

CYBERTRON_END
